\(\int (a+b \tan ^2(c+d x))^2 \, dx\) [252]

   Optimal result
   Rubi [A] (verified)
   Mathematica [A] (verified)
   Maple [A] (verified)
   Fricas [A] (verification not implemented)
   Sympy [A] (verification not implemented)
   Maxima [A] (verification not implemented)
   Giac [B] (verification not implemented)
   Mupad [B] (verification not implemented)

Optimal result

Integrand size = 14, antiderivative size = 46 \[ \int \left (a+b \tan ^2(c+d x)\right )^2 \, dx=(a-b)^2 x+\frac {(2 a-b) b \tan (c+d x)}{d}+\frac {b^2 \tan ^3(c+d x)}{3 d} \]

[Out]

(a-b)^2*x+(2*a-b)*b*tan(d*x+c)/d+1/3*b^2*tan(d*x+c)^3/d

Rubi [A] (verified)

Time = 0.04 (sec) , antiderivative size = 46, normalized size of antiderivative = 1.00, number of steps used = 4, number of rules used = 3, \(\frac {\text {number of rules}}{\text {integrand size}}\) = 0.214, Rules used = {3742, 398, 209} \[ \int \left (a+b \tan ^2(c+d x)\right )^2 \, dx=\frac {b (2 a-b) \tan (c+d x)}{d}+x (a-b)^2+\frac {b^2 \tan ^3(c+d x)}{3 d} \]

[In]

Int[(a + b*Tan[c + d*x]^2)^2,x]

[Out]

(a - b)^2*x + ((2*a - b)*b*Tan[c + d*x])/d + (b^2*Tan[c + d*x]^3)/(3*d)

Rule 209

Int[((a_) + (b_.)*(x_)^2)^(-1), x_Symbol] :> Simp[(1/(Rt[a, 2]*Rt[b, 2]))*ArcTan[Rt[b, 2]*(x/Rt[a, 2])], x] /;
 FreeQ[{a, b}, x] && PosQ[a/b] && (GtQ[a, 0] || GtQ[b, 0])

Rule 398

Int[((a_) + (b_.)*(x_)^(n_))^(p_)*((c_) + (d_.)*(x_)^(n_))^(q_), x_Symbol] :> Int[PolynomialDivide[(a + b*x^n)
^p, (c + d*x^n)^(-q), x], x] /; FreeQ[{a, b, c, d}, x] && NeQ[b*c - a*d, 0] && IGtQ[n, 0] && IGtQ[p, 0] && ILt
Q[q, 0] && GeQ[p, -q]

Rule 3742

Int[((a_) + (b_.)*((c_.)*tan[(e_.) + (f_.)*(x_)])^(n_))^(p_), x_Symbol] :> With[{ff = FreeFactors[Tan[e + f*x]
, x]}, Dist[c*(ff/f), Subst[Int[(a + b*(ff*x)^n)^p/(c^2 + ff^2*x^2), x], x, c*(Tan[e + f*x]/ff)], x]] /; FreeQ
[{a, b, c, e, f, n, p}, x] && (IntegersQ[n, p] || IGtQ[p, 0] || EqQ[n^2, 4] || EqQ[n^2, 16])

Rubi steps \begin{align*} \text {integral}& = \frac {\text {Subst}\left (\int \frac {\left (a+b x^2\right )^2}{1+x^2} \, dx,x,\tan (c+d x)\right )}{d} \\ & = \frac {\text {Subst}\left (\int \left ((2 a-b) b+b^2 x^2+\frac {(a-b)^2}{1+x^2}\right ) \, dx,x,\tan (c+d x)\right )}{d} \\ & = \frac {(2 a-b) b \tan (c+d x)}{d}+\frac {b^2 \tan ^3(c+d x)}{3 d}+\frac {(a-b)^2 \text {Subst}\left (\int \frac {1}{1+x^2} \, dx,x,\tan (c+d x)\right )}{d} \\ & = (a-b)^2 x+\frac {(2 a-b) b \tan (c+d x)}{d}+\frac {b^2 \tan ^3(c+d x)}{3 d} \\ \end{align*}

Mathematica [A] (verified)

Time = 0.67 (sec) , antiderivative size = 73, normalized size of antiderivative = 1.59 \[ \int \left (a+b \tan ^2(c+d x)\right )^2 \, dx=\frac {\tan (c+d x) \left (\frac {3 (a-b)^2 \text {arctanh}\left (\sqrt {-\tan ^2(c+d x)}\right )}{\sqrt {-\tan ^2(c+d x)}}+b \left (6 a-b \left (3-\tan ^2(c+d x)\right )\right )\right )}{3 d} \]

[In]

Integrate[(a + b*Tan[c + d*x]^2)^2,x]

[Out]

(Tan[c + d*x]*((3*(a - b)^2*ArcTanh[Sqrt[-Tan[c + d*x]^2]])/Sqrt[-Tan[c + d*x]^2] + b*(6*a - b*(3 - Tan[c + d*
x]^2))))/(3*d)

Maple [A] (verified)

Time = 0.05 (sec) , antiderivative size = 49, normalized size of antiderivative = 1.07

method result size
norman \(\left (a^{2}-2 a b +b^{2}\right ) x +\frac {\left (2 a -b \right ) b \tan \left (d x +c \right )}{d}+\frac {b^{2} \tan \left (d x +c \right )^{3}}{3 d}\) \(49\)
derivativedivides \(\frac {\frac {b^{2} \tan \left (d x +c \right )^{3}}{3}+2 a b \tan \left (d x +c \right )-b^{2} \tan \left (d x +c \right )+\left (a^{2}-2 a b +b^{2}\right ) \arctan \left (\tan \left (d x +c \right )\right )}{d}\) \(59\)
default \(\frac {\frac {b^{2} \tan \left (d x +c \right )^{3}}{3}+2 a b \tan \left (d x +c \right )-b^{2} \tan \left (d x +c \right )+\left (a^{2}-2 a b +b^{2}\right ) \arctan \left (\tan \left (d x +c \right )\right )}{d}\) \(59\)
parallelrisch \(\frac {b^{2} \tan \left (d x +c \right )^{3}+3 a^{2} d x -6 a b d x +3 b^{2} d x +6 a b \tan \left (d x +c \right )-3 b^{2} \tan \left (d x +c \right )}{3 d}\) \(60\)
parts \(x \,a^{2}+\frac {b^{2} \left (\frac {\tan \left (d x +c \right )^{3}}{3}-\tan \left (d x +c \right )+\arctan \left (\tan \left (d x +c \right )\right )\right )}{d}+\frac {2 a b \left (\tan \left (d x +c \right )-\arctan \left (\tan \left (d x +c \right )\right )\right )}{d}\) \(63\)
risch \(x \,a^{2}-2 x a b +x \,b^{2}-\frac {4 i b \left (-3 a \,{\mathrm e}^{4 i \left (d x +c \right )}+3 b \,{\mathrm e}^{4 i \left (d x +c \right )}-6 a \,{\mathrm e}^{2 i \left (d x +c \right )}+3 b \,{\mathrm e}^{2 i \left (d x +c \right )}-3 a +2 b \right )}{3 d \left ({\mathrm e}^{2 i \left (d x +c \right )}+1\right )^{3}}\) \(92\)

[In]

int((a+b*tan(d*x+c)^2)^2,x,method=_RETURNVERBOSE)

[Out]

(a^2-2*a*b+b^2)*x+(2*a-b)*b*tan(d*x+c)/d+1/3*b^2*tan(d*x+c)^3/d

Fricas [A] (verification not implemented)

none

Time = 0.27 (sec) , antiderivative size = 51, normalized size of antiderivative = 1.11 \[ \int \left (a+b \tan ^2(c+d x)\right )^2 \, dx=\frac {b^{2} \tan \left (d x + c\right )^{3} + 3 \, {\left (a^{2} - 2 \, a b + b^{2}\right )} d x + 3 \, {\left (2 \, a b - b^{2}\right )} \tan \left (d x + c\right )}{3 \, d} \]

[In]

integrate((a+b*tan(d*x+c)^2)^2,x, algorithm="fricas")

[Out]

1/3*(b^2*tan(d*x + c)^3 + 3*(a^2 - 2*a*b + b^2)*d*x + 3*(2*a*b - b^2)*tan(d*x + c))/d

Sympy [A] (verification not implemented)

Time = 0.12 (sec) , antiderivative size = 68, normalized size of antiderivative = 1.48 \[ \int \left (a+b \tan ^2(c+d x)\right )^2 \, dx=\begin {cases} a^{2} x - 2 a b x + \frac {2 a b \tan {\left (c + d x \right )}}{d} + b^{2} x + \frac {b^{2} \tan ^{3}{\left (c + d x \right )}}{3 d} - \frac {b^{2} \tan {\left (c + d x \right )}}{d} & \text {for}\: d \neq 0 \\x \left (a + b \tan ^{2}{\left (c \right )}\right )^{2} & \text {otherwise} \end {cases} \]

[In]

integrate((a+b*tan(d*x+c)**2)**2,x)

[Out]

Piecewise((a**2*x - 2*a*b*x + 2*a*b*tan(c + d*x)/d + b**2*x + b**2*tan(c + d*x)**3/(3*d) - b**2*tan(c + d*x)/d
, Ne(d, 0)), (x*(a + b*tan(c)**2)**2, True))

Maxima [A] (verification not implemented)

none

Time = 0.38 (sec) , antiderivative size = 58, normalized size of antiderivative = 1.26 \[ \int \left (a+b \tan ^2(c+d x)\right )^2 \, dx=a^{2} x - \frac {2 \, {\left (d x + c - \tan \left (d x + c\right )\right )} a b}{d} + \frac {{\left (\tan \left (d x + c\right )^{3} + 3 \, d x + 3 \, c - 3 \, \tan \left (d x + c\right )\right )} b^{2}}{3 \, d} \]

[In]

integrate((a+b*tan(d*x+c)^2)^2,x, algorithm="maxima")

[Out]

a^2*x - 2*(d*x + c - tan(d*x + c))*a*b/d + 1/3*(tan(d*x + c)^3 + 3*d*x + 3*c - 3*tan(d*x + c))*b^2/d

Giac [B] (verification not implemented)

Leaf count of result is larger than twice the leaf count of optimal. 359 vs. \(2 (44) = 88\).

Time = 0.47 (sec) , antiderivative size = 359, normalized size of antiderivative = 7.80 \[ \int \left (a+b \tan ^2(c+d x)\right )^2 \, dx=\frac {3 \, a^{2} d x \tan \left (d x\right )^{3} \tan \left (c\right )^{3} - 6 \, a b d x \tan \left (d x\right )^{3} \tan \left (c\right )^{3} + 3 \, b^{2} d x \tan \left (d x\right )^{3} \tan \left (c\right )^{3} - 9 \, a^{2} d x \tan \left (d x\right )^{2} \tan \left (c\right )^{2} + 18 \, a b d x \tan \left (d x\right )^{2} \tan \left (c\right )^{2} - 9 \, b^{2} d x \tan \left (d x\right )^{2} \tan \left (c\right )^{2} - 6 \, a b \tan \left (d x\right )^{3} \tan \left (c\right )^{2} + 3 \, b^{2} \tan \left (d x\right )^{3} \tan \left (c\right )^{2} - 6 \, a b \tan \left (d x\right )^{2} \tan \left (c\right )^{3} + 3 \, b^{2} \tan \left (d x\right )^{2} \tan \left (c\right )^{3} + 9 \, a^{2} d x \tan \left (d x\right ) \tan \left (c\right ) - 18 \, a b d x \tan \left (d x\right ) \tan \left (c\right ) + 9 \, b^{2} d x \tan \left (d x\right ) \tan \left (c\right ) - b^{2} \tan \left (d x\right )^{3} + 12 \, a b \tan \left (d x\right )^{2} \tan \left (c\right ) - 9 \, b^{2} \tan \left (d x\right )^{2} \tan \left (c\right ) + 12 \, a b \tan \left (d x\right ) \tan \left (c\right )^{2} - 9 \, b^{2} \tan \left (d x\right ) \tan \left (c\right )^{2} - b^{2} \tan \left (c\right )^{3} - 3 \, a^{2} d x + 6 \, a b d x - 3 \, b^{2} d x - 6 \, a b \tan \left (d x\right ) + 3 \, b^{2} \tan \left (d x\right ) - 6 \, a b \tan \left (c\right ) + 3 \, b^{2} \tan \left (c\right )}{3 \, {\left (d \tan \left (d x\right )^{3} \tan \left (c\right )^{3} - 3 \, d \tan \left (d x\right )^{2} \tan \left (c\right )^{2} + 3 \, d \tan \left (d x\right ) \tan \left (c\right ) - d\right )}} \]

[In]

integrate((a+b*tan(d*x+c)^2)^2,x, algorithm="giac")

[Out]

1/3*(3*a^2*d*x*tan(d*x)^3*tan(c)^3 - 6*a*b*d*x*tan(d*x)^3*tan(c)^3 + 3*b^2*d*x*tan(d*x)^3*tan(c)^3 - 9*a^2*d*x
*tan(d*x)^2*tan(c)^2 + 18*a*b*d*x*tan(d*x)^2*tan(c)^2 - 9*b^2*d*x*tan(d*x)^2*tan(c)^2 - 6*a*b*tan(d*x)^3*tan(c
)^2 + 3*b^2*tan(d*x)^3*tan(c)^2 - 6*a*b*tan(d*x)^2*tan(c)^3 + 3*b^2*tan(d*x)^2*tan(c)^3 + 9*a^2*d*x*tan(d*x)*t
an(c) - 18*a*b*d*x*tan(d*x)*tan(c) + 9*b^2*d*x*tan(d*x)*tan(c) - b^2*tan(d*x)^3 + 12*a*b*tan(d*x)^2*tan(c) - 9
*b^2*tan(d*x)^2*tan(c) + 12*a*b*tan(d*x)*tan(c)^2 - 9*b^2*tan(d*x)*tan(c)^2 - b^2*tan(c)^3 - 3*a^2*d*x + 6*a*b
*d*x - 3*b^2*d*x - 6*a*b*tan(d*x) + 3*b^2*tan(d*x) - 6*a*b*tan(c) + 3*b^2*tan(c))/(d*tan(d*x)^3*tan(c)^3 - 3*d
*tan(d*x)^2*tan(c)^2 + 3*d*tan(d*x)*tan(c) - d)

Mupad [B] (verification not implemented)

Time = 10.43 (sec) , antiderivative size = 76, normalized size of antiderivative = 1.65 \[ \int \left (a+b \tan ^2(c+d x)\right )^2 \, dx=\frac {\mathrm {tan}\left (c+d\,x\right )\,\left (2\,a\,b-b^2\right )}{d}+\frac {\mathrm {atan}\left (\frac {\mathrm {tan}\left (c+d\,x\right )\,{\left (a-b\right )}^2}{a^2-2\,a\,b+b^2}\right )\,{\left (a-b\right )}^2}{d}+\frac {b^2\,{\mathrm {tan}\left (c+d\,x\right )}^3}{3\,d} \]

[In]

int((a + b*tan(c + d*x)^2)^2,x)

[Out]

(tan(c + d*x)*(2*a*b - b^2))/d + (atan((tan(c + d*x)*(a - b)^2)/(a^2 - 2*a*b + b^2))*(a - b)^2)/d + (b^2*tan(c
 + d*x)^3)/(3*d)